<?php

class Tag{

	var $db;

	public function __construct(){
		$this->db = new DBClass();
	}
	
	public function get_all_tag(){
		
		$query = "Select * from tag order  by id_tag desc";

		$rows = $this->db->getRows($query);

		return $rows;	

	}

	public function addtag($data){
		
		$query ="INSERT INTO tag SET jdl_tag='".@$data['jdl_tag']."', slug_tag='".@$data['slug_tag']."',deskripsi_tag='".@$data['deskripsi_tag']."'";

		$rows = $this->db->putRows($query);

		header('Location: tag.php');
	}

	public function editTag($data){
		
		$query ="UPDATE tag SET jdl_tag='".@$data['jdl_tag']."',deskripsi_tag='".@$data['deskripsi_tag']."',slug_tag='".@$data['slug_tag']."' WHERE id_tag='".@$data['idtag']."'";

		$this->db->putRows($query);
		
		header('Location: tag.php');
	}

	public function deleteTag($data){
		
		$query ="DELETE FROM tag WHERE id_tag='".@$data."'";

		$rows = $this->db->getRows($query);

		header('Location: tag.php');
	}

	public function getTag($data){
		
		$query ="SELECT * FROM tag WHERE id_tag=".@$data;

		$rows = $this->db->getRows($query);
		return array_shift($rows);
	}
}